<?
	header("Content-Type: application/xml; charset=utf-8");
	$functions_uri = dirname(__FILE__) . "/drizzo/engine/functions.php";
	require_once($functions_uri);
	$uri_vars = drizzo_parse_the_uri();
	$drizzo_offset = $uri_vars['offset'];
	$drizzo_post_id = $uri_vars['post_id'];
	$drizzo_page_type = $uri_vars['page_type'];
	$drizzo_feed = $uri_vars['feed'];
?>
<? echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/">
<?
	if(!$drizzo_post_id) { // Default Blog Feed
?>
	<channel>
		<title><? echo drizzo_site_name(); ?></title>
		<link><? echo domain; ?></link>
		<description><? echo drizzo_site_description(); ?></description>
		<pubDate><? echo date('D, d M Y H:i:s +0000', drizzo_last_post_date()); ?></pubDate>
		<generator>Drizzo <? echo drizzo_version_number(); ?></generator>

<?			
		$the_posts = drizzo_get_the_posts(10, 0, "publish", "blog"); // Start the Loop
		if($the_posts) {
			foreach($the_posts as $the_post) {
?>
		<item>
			<title><? echo drizzo_post_title(); ?></title>
			<link><? echo drizzo_post_permalink(); ?></link>
			<guid isPermaLink="false"><? echo domain . "-" . $the_post['ID']; ?></guid>
			<pubDate><? echo drizzo_post_date('D, d M Y H:i:s +0000'); ?></pubDate>
			<dc:creator><? echo drizzo_post_author("nice_name"); ?></dc:creator>
			<description><![CDATA[<? echo drizzo_post_content(); ?><p><strong>Tags:</strong> <? echo drizzo_post_tags($the_post['ID'],'comma',false); ?></p>]]></description>
		</item>
<?
			}
		}
?>
		
	</channel>
<?
	} elseif($drizzo_page_type == 'tags') { // Tag Feed
?>
	<channel>
		<title><? echo drizzo_site_name(); ?> - Tag "<? echo $drizzo_post_id; ?>"</title>
		<link><? echo domain; ?>/tags/<? echo $drizzo_post_id; ?></link>
		<description>Feed for posts tagged with "<? echo $drizzo_post_id; ?>"</description>
		<pubDate><? echo date('D, d M Y H:i:s +0000', drizzo_last_tag_date($drizzo_post_id)); ?></pubDate>
		<generator>Drizzo <? echo drizzo_version_number(); ?></generator>
<?
		$the_posts = drizzo_tag_search($drizzo_post_id);
		if($the_posts) { // Posts are found
			foreach($the_posts as $the_post) {
?>
		<item>
			<title><? echo drizzo_post_title(); ?></title>
			<link><? echo drizzo_post_permalink(); ?></link>
			<guid isPermaLink="false"><? echo domain . "-" . $the_post['ID']; ?></guid>
			<pubDate><? if((drizzo_post_edit_date("raw") - drizzo_post_date("raw")) > 10*60) { echo "-" . drizzo_post_edit_date("raw"); } else { echo drizzo_post_date('D, d M Y H:i:s +0000'); } ?></pubDate>
			<dc:creator><? echo drizzo_post_author("nice_name"); ?></dc:creator>
			<description><![CDATA[<p><strong>By <? echo drizzo_post_author("nice_name"); ?> on <? echo drizzo_post_date('D, M j, Y \a\t g:i A'); if((drizzo_post_edit_date("raw") - drizzo_post_date("raw")) > 10*60) { echo " (Updated: " . drizzo_post_edit_date('D, M j, Y \a\t g:i A') . ")"; } ?></strong></p><? echo drizzo_post_content(); ?><p><strong>Tags:</strong> <? echo drizzo_post_tags($the_post['ID'],'comma',false); ?></p>]]></description>
		</item>
<?
			}
		} else { // No posts are found
?>
		<item>
			<title>No Posts</title>
			<link><? echo domain; ?></link>
			<guid isPermaLink="false"><? echo domain . "-" . $drizzo_post_id . "-0000"; ?></guid>
			<pubDate><? echo date('D, d M Y H:i:s +0000'); ?></pubDate>
			<dc:creator>Drizzo <? echo drizzo_version_number(); ?></dc:creator>
			<description>Nothing has been tagged with "<? echo $drizzo_post_id; ?>".</description>
		</item>
<?
		}
?>
	</channel>
<?
	} else { // Post Comments Feed
?>
	<channel>
<?
		$id = drizzo_get_post_id($drizzo_post_id);
		$the_post = (drizzo_get_the_post($id)); // Start the Loop
?>
		<title><? echo drizzo_site_name(); ?> - "<? echo drizzo_post_title(); ?>"</title>
		<link><? echo drizzo_post_permalink(); ?></link>
		<description>Comment feed for post "<? echo drizzo_post_title(); ?>" at <? echo drizzo_site_name(); ?>. Original post shown first.</description>
		<pubDate><? if((drizzo_post_edit_date("raw") - drizzo_post_date("raw")) > 10*60) { echo "-" . drizzo_post_edit_date("raw"); } else { echo drizzo_post_date('D, d M Y H:i:s +0000'); } ?></pubDate>
		<generator>Drizzo <? echo drizzo_version_number(); ?></generator>

		<item>
			<title><? echo drizzo_post_title(); ?></title>
			<link><? echo drizzo_post_permalink(); ?></link>
			<guid isPermaLink="false"><? echo domain . "-" . $the_post['ID']; if(drizzo_post_date("raw") < drizzo_post_edit_date("raw")) { echo "-" . drizzo_post_edit_date("raw"); } ?></guid>
			<pubDate><? if(drizzo_post_date("raw") < drizzo_post_edit_date("raw")) { echo "-" . drizzo_post_edit_date("raw"); } else { echo drizzo_post_date('D, d M Y H:i:s +0000'); } ?></pubDate>
			<dc:creator><? echo drizzo_post_author("nice_name"); ?></dc:creator>
			<description><![CDATA[<p><strong>By <? echo drizzo_post_author("nice_name"); ?> on <? echo drizzo_post_date('D, M j, Y \a\t g:i A'); if((drizzo_post_edit_date("raw") - drizzo_post_date("raw")) > 10*60) { echo " (Updated: " . drizzo_post_edit_date('D, M j, Y \a\t g:i A') . ")"; } ?></strong></p><? echo drizzo_post_content(); ?><p><strong>Tags:</strong> <? echo drizzo_post_tags($the_post['ID'],'comma',false); ?></p>]]></description>
		</item>

<?			
		$comments = drizzo_get_the_comments($id); // Start the Comments Loop
		if($comments) { // If there are comments
			foreach($comments as $comment) {
?>
		<item>
			<title><? if(strlen($comment['title']) > 0) { echo $comment['title']; } else { echo "(Untitled)"; } ?></title>
			<link><? echo drizzo_post_permalink(); ?>#comment-<? echo $comment['ID']; ?></link>
			<guid isPermaLink="false"><? echo domain . "-comment-" . $comment['ID']; ?></guid>
			<pubDate><? echo date('D, d M Y H:i:s +0000', $comment['date']); ?></pubDate>
			<dc:creator><? echo $comment['author']; ?></dc:creator>
			<description><![CDATA[<p><strong>By <? echo $comment['author']; ?> on <? echo date('D, M j, Y H:i A', $comment['date']); ?></strong></p><? echo $comment['content']; ?>]]></description>
		</item>
<?
			}
		} else { // If there are no comments
?>
		<item>
			<title>No Comments</title>
			<link><? echo drizzo_post_permalink(); ?>#comments</link>
			<guid isPermaLink="false"><? echo domain . "-" . $drizzo_post_id . "-0000"; ?></guid>
			<pubDate><? echo drizzo_post_date('D, d M Y H:i:s +0000'); ?></pubDate>
			<dc:creator><? echo drizzo_post_author("nice_name"); ?></dc:creator>
			<description>No comments have been made yet.</description>
		</item>
<?		
		}
?>
		
	</channel>
<?
	}
?>
</rss>